package com.xudow.app.util;

import android.content.Context;
import android.net.ConnectivityManager;

/**
 * Network utils
 *
 * @author scott
 */

public class NetworkUtils {

    /**
     * 判断是否联网
     *
     * @param ctx
     * @return
     */
    public static boolean isNetWorkConnected(Context ctx) {
        try {
            ConnectivityManager conManager =
                    (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
            try {
                conManager.getActiveNetworkInfo();
            } catch (Exception e) {
                return false;
            }

            if (conManager.getActiveNetworkInfo() == null
                    || !conManager.getActiveNetworkInfo().isAvailable()) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
    }
}
